<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../../component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <div class="layui-select-group">
                        <select id="selectEquipment" name="equipmentId" lay-verify="" lay-search>
                            <option value="">请选择一个设备</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">出入库类型</label>
                    <div class="layui-input-block">
                        <input type="radio" name="inAndOutType" value="1" title="出库" checked>
                        <input type="radio" name="inAndOutType" value="2" title="入库">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">检查人姓名</label>
                    <div class="layui-input-block">
                        <input type="text"  name="checkUserName" lay-verify="require" autocomplete="off" placeholder="请输入检查人姓名" class="layui-input">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit lay-filter="warehouseRecord-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>
<script>
layui.use(['form','jquery'],function(){
    let form = layui.form;
    let $ = layui.jquery;

    $.ajax({
        url:'/equipment/queryEquipment',
        type:'get',
        success: function (result) {
            if(result.code === 0) {
                for (let i = 0; i < result.data.length; i++) {
                    $('#selectEquipment').append(new Option(result.data[i].equipmentName, result.data[i].id)); //将数据放到option中
                }
                form.render('select');//重新渲染下拉框，如果不重新渲染下拉框是不出来的
            }
        }
    });

    form.on('submit(warehouseRecord-save)', function(data){
        console.log(JSON.stringify(data));
        $.ajax({
            url:'/warehouseRecord/addWarehouseRecord',
            data:JSON.stringify(data.field),
            dataType:'json',
            contentType:'application/json',
            type:'post',
            success:function(result){
                if(result.code === 0){
                    layer.msg(result.msg,{icon:1,time:1000},function(){
                        parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        parent.layui.table.reload("warehouseRecord-table");
                    });
                }else{
                    layer.msg(result.msg,{icon:2,time:1000});
                }
            }
        })
        return false;
    });
})
</script>
<script>
</script>
</body>
</html>